package jimo.SSMStudent.service.impl;

import jimo.SSMStudent.mapper.StudentMapper;
import jimo.SSMStudent.pojo.Student;
import jimo.SSMStudent.pojo.StudentExample;
import jimo.SSMStudent.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    /***
     * 添加student
     * @param student
     * @return
     */
    @Override
    public int insert(Student student) {
        return  studentMapper.insert(student);

    }

    /***
     * 删除
     * @param id
     * @return
     */
    @Override
    public int delById(int id) {
        return studentMapper.deleteByPrimaryKey(id);

    }

    /***
     * 修改student
     * @param student 修改的参数
     * @return
     */
    @Override
    public int update(Student student) {
        student.setRegdate(new Date());
        return studentMapper.updateByPrimaryKeySelective(student);
    }

    /***
     * 查询单个依据id
     * @param id
     * @return
     */
    @Override
    public Student selectById(int id) {
        return studentMapper.selectByPrimaryKey(id);
    }

    /***
     * 模糊查询全部
     * @param studentExample 查询条件
     * @return
     */
    @Override
    public List<Student> selects(StudentExample studentExample) {
        return studentMapper.selectByExample(studentExample);
    }
}
